####
#### Eroll Kuhn & Rahsaan Maxwell
#### Generating Histograms of two outcome variables
#### 02.26.2020



rm(list=ls())

# read in frame
df <- read.csv(".../3.Outcomes Descriptive/Output/B.Tables/Combined_Tables.csv")


# pre-processing
df <- data.frame(df)


## outcome subsets and recode outcome
df_factor <- subset(df,df$Outcome=="Factor")
df_factor_weighted <- subset(df,(df$Outcome=="Factor" & df$Type=="Weighted"))

## index
df_index <- subset(df,df$Outcome=="Index")
df_index_weighted <- subset(df,(df$Outcome=="Index" & df$Type=="Weighted"))

rm(df)

## plot
library(ggplot2)
cbPalette <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7", "#000000")

###############
#index
setwd(".../3.Outcomes Descriptive/Output/D.Figures")


png("index_histogram_weightedOnly.png",
    width=10,height=6,units='in',res=300)
ggplot(data = df_index_weighted, aes(y = as.numeric(Prop),
                            x=as.numeric(Numeric))) + 
  geom_col() +
  facet_wrap(~Type) +
  xlab("Welcomeness Index") +
  ylab("Proportion of Responses") +
theme_bw() +
  theme(legend.direction = "horizontal",
        legend.position = "bottom",
        panel.grid.major.x = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major.y = element_line(size = .15, linetype = 2, color = "gray75")) 
dev.off()

###########################
# factor


png("factor_histogram_weighted.png",
    width=10,height=6,units='in',res=300)
ggplot(data = df_factor_weighted, aes(y = as.numeric(Prop),
                             x=as.numeric(Numeric))) + 
  geom_col(width =0.005) +
  facet_wrap(~Type) +
  xlab("Welcomeness Factor") +
  ylab("Proportion of Responses") +
theme_bw() +
  theme(legend.direction = "horizontal",
        legend.position = "bottom",
        panel.grid.major.x = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major.y = element_line(size = .15, linetype = 2, color = "gray75")) 
dev.off()

